//
//  SignExpertMainViewController.m
//  StraightTrain
//
//  Created by mk on 15/11/25.
//  Copyright (c) 2015年 mk. All rights reserved.
//

#import "SignExpertMainViewController.h"
#import "SignExpertAgreementViewController.h"//协议


@interface SignExpertMainViewController ()
{
    NSString * strOldMess;

}

@end

@implementation SignExpertMainViewController


-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
   // [[NSNotificationCenter defaultCenter] addObserver:self
   //                                          selector:@selector(keyboardWillShow:)
   //                                              name:UIKeyboardWillShowNotification
   //                                            object:nil];
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [txtMess resignFirstResponder];
    
   // [[NSNotificationCenter defaultCenter] removeObserver:self
   //                                                 name:UIKeyboardWillShowNotification
   //                                               object:nil];
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [scrollMain setAlwaysBounceVertical:YES];
    strOldMess = @"";
    titleLabel.text = @"签约专家";
    txtMess.layer.cornerRadius = 8;
    [scrollMain setAlwaysBounceVertical:YES];
    [self loadSignStateData];
}


-(void)loadSignStateData
{
    NSString * strUrl = [NSString stringWithFormat:@"http://api.mingyizhudao.com/apimd/profile?username=%@&token=%@",[gProjConfig.dicUserData objectForKey:USER_tel],[gProjConfig.dicUserData objectForKey:USER_token]];
    
    [[HttpClient manager]GET:strUrl
                  parameters:nil
     success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         id data = [responseObject objectForKey:requestDataKey];
         if ([data isKindOfClass:[NSDictionary class]])
         {
             strOldMess = NullObjToString([data objectForKey:@"preferred_patient"]);
             txtMess.text = strOldMess;
         }
      // DLog(@"%@",responseObject)
         
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         HUDShowRequestError(error.domain, self.view)
     }];
    
}


-(IBAction)AgreementMessage:(id)sender
{
    if ([txtMess.text isEqualToString:strOldMess])
    {
        Alert(alerTitle, @"没有修改任何信息", @"确定");
        return;
    }
    
    SignExpertAgreementViewController * agreemet = [[SignExpertAgreementViewController alloc]initWithNibName:@"SignExpertAgreementViewController" bundle:nil];
    agreemet.strMess = txtMess.text;
    [self.navigationController pushViewController:agreemet animated:YES];
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [txtMess resignFirstResponder];
        //[scrollMain setContentOffset:CGPointMake(0,0) animated:YES];
        return NO;
    }
    return YES;
}


- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [txtMess resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
